<template>
  <div class="article">
    <!-- 切换按钮 -->
    <div class="tabBar">
      <div class="tab">
        <div class="suggest active" ref="suggest" @click="clicked('suggest')">
          推荐
          <div class="line"></div>
        </div>
        <div class="new" ref="new" @click="clicked('new')">
          最新
          <div class="line"></div>
        </div>
      </div>
      <img src="../assets/logo.interview.png" class="logo" />
    </div>
    <!-- 面经列表入口 -->
    <router-view></router-view>
  </div>
</template>

<script>
// 导入请求
import { UserRequest } from "@/api/user";
export default {
  data() {
    return {
      list: [],
      loading: false,
    };
  },
  methods: {
    getDetail(id) {
      this.$router.push({
        path: "/detail",
        query: {
          id: id,
        },
      });
    },
    clicked(ref) {
      if (ref === "suggest") {
        this.$refs.new.classList.remove("active");
        this.$refs.suggest.classList.add("active");
        this.$router.push({
          path: "/layout/article/suggestList",
        });
      } else if (ref === "new") {
        this.$refs.new.classList.add("active");
        this.$refs.suggest.classList.remove("active");
        this.$router.push({
          path: "/layout/article/newlist",
        });
      }
    },
    //获取推荐列表
    getSuggestList(token) {
      UserRequest.getSuggestList(token).then((res) => {
        console.log(res.data.data.rows);
        this.list = res.data.data.rows;
        console.log(this.list);
      });
    },
    //获取最新列表
    getNewList(token) {
      UserRequest.getNewList(token).then((res) => {
        this.list = res.data.data.rows;
        console.log(this.list);
      });
    },
  },
  created() {},
};
</script>

<style lang="less" scoped>
.tabBar {
  height: (44 / @vw);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: white;
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 999;

  .tab {
    height: (44 / @vw);
    display: flex;
    margin-left: (20 / @vw);
    .suggest {
      margin-right: (20 / @vw);
      line-height: (44 / @vw);
      height: 100%;
      position: relative;
      font-size: (14 / @vw);
      color: #ccc;
      .line {
        position: absolute;
        // display: none;
        bottom: 0;
        left: 50%;
        translate: -50%;
        width: (0 / @vw);
        height: (2 / @vw);
        background-color: #222;
        transition: all 0.4s;
      }
    }
    .new {
      color: #ccc;
      height: 100%;
      position: relative;
      line-height: (44 / @vw);
      font-size: (14 / @vw);
      transition: all 0.4s;

      .line {
        // display: none;
        position: absolute;
        bottom: 0;
        left: 50%;
        translate: -50%;
        width: (0 / @vw);
        height: (2 / @vw);
        background-color: #222;
      }
    }
    .active {
      color: #000;
      .line {
        display: block;
        width: (14 / @vw);
        transition: all 0.4s;
      }
    }
  }

  .logo {
    margin-right: (20 / @vw);
    width: (64 / @vw);
    height: (28 / @vw);
  }
}
</style>
